

$(document).ready( function() {

  var html = "";

  html += "<table border='1px'>";
  html += "  <thead>";
  html += "    <tr>";
  html += "      <th id='test' rowspan='2'>Test<br/>ID</th>";
  html += "      <th id='desc' rowspan='2'>Description</th>";
  html += "      <th id='stat' rowspan='2'>States</th>";
  html += "      <th id='prop' rowspan='2'>Properties</th>";
  html += "      <th id='msaa' colspan='2' class='col1'>Windows 7 <abbr title='Microsoft Active Accessibility'>MSAA</abbr> &amp; <abbr title='IAccessible2'>IA2</abbr></th>";
  html += "      <th id='osx'  colspan='2' class='col2'>OS X 10.6</th>";
  html += "      <th id='unix' colspan='2' class='col3'>Unix/Linux</th>";
  html += "      <th id='uia'  colspan='2' class='col4'>Windows 7 UI Automation</th>";
  html += "      <th id='sr'   colspan='2' class='col5'>Screen Reader</th>";
  html += "    </tr>";
  html += "    <tr>";
  html += "      <th id='mr'  class='col11'>Mapping Results</th>";
  html += "      <th id='anr' class='col12'>Accessible Name Results</th>";
  html += "      <th class='col21'>Mapping Results</th>";
  html += "      <th class='col22'>Accessible Name Results</th>";
  html += "      <th class='col31'>Mapping Results</th>";
  html += "      <th class='col32'>Accessible Name Results</th>";
  html += "      <th class='col41'>Mapping Results</th>";
  html += "      <th class='col42'>Accessible Name Results</th>";
  html += "      <th class='col51'>Mapping Results</th>";
  html += "      <th class='col52'>Accessible Name Results</th>";
  html += "    </tr>";
  html += "  </thead>";

  for(var i = 0; i < aria_test_results.results.length; i++ ) {
  
    var id = aria_test_results.results[i].id.split("_");    
    var group = parseInt(id[1]);
    var num   = parseInt(id[2]);
    var test_id = "test" + group + "_" + num; 

    html += "  <tbody>";
    html += "    <tr>";
    html += "      <th id='" + test_id + "'>" + group + "." + num + "</th>";
    html += "      <td headers='" + test_id + " desc'>";
    html += "        <a href='" + aria_test_results.results[i].file + "'>"+ aria_test_results.results[i].title + "</a>";
    html += "      </td>";
    // States
    html += "      <td headers='" + test_id + " stat'>";
    html += "        <ul>";
    var states = aria_test_results.results[i].states;
    for(var j=0; j < states.length; j++) {
      html += "        <li>" + states[j] +  "</li>";  
    } // endfor    
    html += "         </ul>";
    html += "       </td>";

    // Properties
    html += "      <td headers='" + test_id + " prop'>";
    html += "        <ul>";
    var properties = aria_test_results.results[i].properties;
    for(var j=0; j < properties.length; j++) {
      html += "        <li>" + properties[j] +  "</li>";  
    } // endfor    
    html += "         </ul>";
    html += "       </td>";
    
    var win7 = aria_test_results.results[i].results.win7;
    if( win7 ) {
      html += "      <td headers='" + test_id + " msaa mr'  class='col11'>";
      html += "        <ul>";
      for(var j=0; j < win7.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[win7[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[win7[j].result] + "</li>";  
      } // endfor
      html += "        </ul>";    
      html += "      </td>";
    

      html += "      <td headers='" + test_id + " msaa anr' class='col12'>";
      html += "        <ul>";
    
      for(var j=0; j < win7.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[win7[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[win7[j].accessible_name] + "</li>";  
      } // endfor
      html += "        </ul>";    
      html += "      </td>";
    } else {
      html += "      <td headers='" + test_id + " osx mr' class='col31'><span class='nr'>no results</span></td>";
      html += "      <td headers='" + test_id + " osx anr' class='col32'><span class='nr'>no results</span></td>";    
    } // endif  
    
    

    var osx = aria_test_results.results[i].results.osx106;
    if( osx ) {
      html += "      <td headers='" + test_id + " osx mr' class='col21'>";
      html += "        <ul>";    
    
      for(var j=0; j < osx.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[osx[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[osx[j].result] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
 
      html += "      <td headers='" + test_id + " osx anr' class='col22'>"
      html += "        <ul>";    
    
      for(var j=0; j < osx.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[osx[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[osx[j].accessible_name] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
    } else {
      html += "      <td headers='" + test_id + " osx mr' class='col31'><span class='nr'>no results</span></td>";
      html += "      <td headers='" + test_id + " osx anr' class='col32'><span class='nr'>no results</span></td>";    
    } // endif  
    
    
    var unix = aria_test_results.results[i].results.unix;
    if( unix ) {
      html += "      <td headers='" + test_id + " unix mr' class='col31'>";
      html += "        <ul>";    
    
      for(var j=0; j < unix.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[unix[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[unix[j].result] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
 
      html += "      <td headers='" + test_id + " unix anr' class='col32'>"
      html += "        <ul>";    
    
      for(var j=0; j < unix.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[unix[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[unix[j].accessible_name] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
    } else {
      html += "      <td headers='" + test_id + " unix mr' class='col31'><span class='nr'>no results</span></td>";
      html += "      <td headers='" + test_id + " unix anr' class='col32'><span class='nr'>no results</span></td>";    
    } // endif  
    
    var win7uia = aria_test_results.results[i].results.win7uia;
    if( win7uia ) {
      html += "      <td headers='" + test_id + " uia mr' class='col41'>";
      html += "        <ul>";    

      for(var j=0; j < win7uia.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[win7uia[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[win7uia[j].result] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
 
      html += "      <td headers='" + test_id + " uia anr' class='col42'>"
      html += "        <ul>";    
    
      for(var j=0; j < win7uia.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[win7uia[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[win7uia[j].accessible_name] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
    } else {
      html += "      <td headers='" + test_id + " uia mr' class='col41'>no results</td>";
      html += "      <td headers='" + test_id + " uia mr' class='col42'>no results</td>";    
    } // endif  
    
    
    var sr = aria_test_results.results[i].results.sr;
    if( sr ) {

      html += "      <td headers='" + test_id + " sr mr' class='col51'>";
      html += "        <ul>";    

      for(var j=0; j < sr.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[sr[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[sr[j].result] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";
 
      html += "      <td headers='" + test_id + " sr anr' class='col52'>"
      html += "        <ul>";    
    
      for(var j=0; j < sr.length; j++) {
        html += "        <li>" + ARIA_TEST_CONSTANTS.USER_AGENT[sr[j].name] + " " + ARIA_TEST_CONSTANTS.RESULT[sr[j].accessible_name] + "</li>";  
      } // endfor
    
      html += "        </ul>";    
      html += "      </td>";   
    } else {
      html += "      <td headers='" + test_id + " sr mr'  class='col41'><span class='nr'>no results</span></td>";
      html += "      <td headers='" + test_id + " sr anr' class='col42'><span class='nr'>no results</span></td>";    
    } // endif  



    html += "    </tr>";
    
    html += "  </tbody>";
  }  // end for 

  html += "</table>";

  $('div#content').append(html);

  }  // end ready function
) // end ready event